package com.he.algorithm.search;

/**
 * @description: 顺序查找
 * @Author: HCL
 * @Date: 2024/8/27 8:57
 */
public class OrderSearch {

    public static int search(int[] nums, int target) {
        int res = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == target) {
                res = i;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums = {7, 1, 3, 9, 5, 2, 6};
        int res = search(nums, 3);
        if (res == -1) {
            System.out.println("没有该数据");
        } else {
            System.out.println("位置为：" + res);
        }
    }
}
